package com.fili.gui.components;

import com.fili.core.keygen.EncodedPermission;
import com.fili.core.params.DryConfig;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 23, 2006
 * Time: 11:42:04 AM
 * Revision: 0
 */
public class ToolsPanel extends JPanel
{
    private JComboBox cbUscator;
    private JPanel midPanel;
    private JPanel lowPanel;

    private int currentIndex;


    public int getCurrentIndex()
    {
        return currentIndex;
    }

    public void setCurrentIndex(int currentIndex)
    {
        int oldIndex = this.currentIndex;

        this.currentIndex = currentIndex;
        cbUscator.setSelectedIndex(currentIndex);
        if (oldIndex != currentIndex)
            indexChanged();
    }

    public ToolsPanel()
    {
        setLayout(new BorderLayout());

        JPanel pnl = new JPanel(null);
        pnl.setPreferredSize(new Dimension(40, 40));

        EncodedPermission ep = DryConfig.getConfig().getEncodedPermission();
        String[] items = new String[ep.nrUsc];
        for (int i = 0; i < ep.nrUsc; i++)
            items[i] = "Uscator " + (i + 1);
        cbUscator = new JComboBox(items);

        cbUscator.setBounds(10, 10, 100, 24);
        cbUscator.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                setCurrentIndex(cbUscator.getSelectedIndex());
            }
        });
        pnl.add(cbUscator);

        add(pnl, BorderLayout.NORTH);

        midPanel = new JPanel();
        midPanel.setBackground(Color.white);
        add(midPanel, BorderLayout.CENTER);

        lowPanel = new JPanel();
        add(lowPanel, BorderLayout.SOUTH);
    }

    public void setMainPanel(JComponent comp)
    {
        midPanel.removeAll();
        if (comp != null)
        {
            midPanel.setLayout(new BorderLayout());
            midPanel.add(comp, BorderLayout.CENTER);
        }
        midPanel.repaint();
    }

    public void setLowerPanel(JComponent comp)
    {
        lowPanel.removeAll();
        if (comp != null)
        {
            lowPanel.setLayout(new BorderLayout());
            lowPanel.add(comp, BorderLayout.CENTER);
        }
        lowPanel.repaint();
    }

    protected void indexChanged()
    {
    }
}
